package core
{
	import events.GameDataEvent;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class Model extends EventDispatcher
	{
		public function Model()
		{
		}
		
		private static var _instance:Model;
		
		public static function get instance():Model {
			if(_instance == null){
				_instance = new Model();
			}
			return _instance;
		}
		
		private var _score:int;
		
		private var _level:int;
		
		private var _life:int;
		
		private var _frames:int;
		private var _totalNum:int;
		private var _clearNum:int;
		
		private var _speedTimes:Number;
		
		public var isOver:Boolean;
		
		public function init():void {
			this.score = 0;
			this.level = 0;
			this.life = 30000;
		}
		
		public function levelUp():void {
			this._level = (this._level + 1);
			this._frames = (3 + (int(((this.level - 1) / 3)) * 1));
			this._frames = 5;
			this._speedTimes = (1 + (int(((this.level - 1) / 3)) * 0.1));
			this._totalNum = (((this._level - 1) * 20) + 100);
			if (this._totalNum > 400){
				this._totalNum = 400;
			}
			if (this._speedTimes > 2.5){
				this._speedTimes = 2.5;
			}
			this._clearNum = 0;
			this.isOver = false;
		}
		
		public function get level():int {
			return this._level;
		}
		
		public function get frames():int{
			return this._frames;
		}
		public function get score():int{
			return this._score;
		}
		
		public function get speedTimes():Number{
			return this._speedTimes;
		}
		
		public function get clearNum():int{
			return this._clearNum;
		}
		
		public function get life():int{
			return this._life;
		}
		
		public function get totalNum():int{
			return this._totalNum;
		}
		
		public function set score(value:int):void{
			this._score = value;
			this.dispatchEvent(new GameDataEvent(GameDataEvent.UPDATE_SCORE_EVENT));
		}
		
		public function set life(value:int):void{
			this._life = value;
			this.dispatchEvent(new GameDataEvent(GameDataEvent.UPDATE_LIFE_EVENT));
		}
		
		public function set level(value:int):void{
			this._level = value;
			this.dispatchEvent(new GameDataEvent(GameDataEvent.UPDATE_LEVEL_EVENT));
		}
		
		public function set clearNum(value:int):void{
			this._clearNum = value;
			this.dispatchEvent(new GameDataEvent(GameDataEvent.UPDATE_CLEAR_NUM));
		}
		
		public function get percent():int {
			var result:int = int((this.clearNum / this.totalNum) * 100);
			if (result > 100){
				result = 100;
			}
			return result;
		}
		
		private var _combo:int;
		
		public function set combo(value:int):void {
			this._combo = value;
		}
		
		public function get combo():int {
			return this._combo;
		}
	}
}